home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / overview / dtscpluslibrary / sources / tracer.cp < prev    next >
Encoding:
Text File  |  2000-06-23  |  2.2 KB  |  73 lines

  1. /*
  2.     File:        Tracer.cp
  3.  
  4.     Contains:    TTracer is an example of a stack/heap based tracing class, which could be
  5.                   used for tracing memory leaks and keeping track of created objects
  6.                   TTracer.cp contains the class body information for the initial class construction.
  7.  
  8.     Written by: Kent Sandvik    
  9.  
  10.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  11.  
  12.                 You may incorporate this Apple sample source code into your program(s) without
  13.                 restriction. This Apple sample source code has been provided "AS IS" and the
  14.                 responsibility for its operation is yours. You are not permitted to redistribute
  15.                 this Apple sample source code as "Apple sample source code" after having made
  16.                 changes. If you're going to re-distribute the source, we require that you make
  17.                 it clear in the source that the code was descended from Apple sample source
  18.                 code, but that you've made changes.
  19.  
  20.     Change History (most recent first):
  21.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  22.                 
  23.  
  24. */
  25. // Include files
  26. #ifndef _TRACER_
  27. #include "Tracer.h"
  28. #endif
  29.  
  30.  
  31. // _________________________________________________________________________________________________________ //
  32. // TTracer class member function implementations
  33.  
  34. //    CONSTRUCTORS & DESTRUCTORS
  35. #pragma segment Tracer                       
  36. TTracer::TTracer(const char* label,
  37.                  const char* file,
  38.                  int line) :
  39.     fLabel(label),
  40.     fFile(file),
  41.     fLine(line)
  42. // Default constructor.
  43. {
  44.     fReferenceCount++;
  45.  
  46.     cout << "File " << fFile << " ; Line " << fLine << "  #+++ constructor event in " << fLabel << " (reference count = " << fReferenceCount << ")\n";
  47. }
  48.  
  49.  
  50. #pragma segment Tracer
  51. TTracer::~TTracer()
  52. // Default destructor.
  53. {
  54.     fReferenceCount--;
  55.     cout << "File " << fFile << " ; Line " << fLine << "  #--- destructor  event in " << fLabel << " (reference count = " << fReferenceCount << ")\n";
  56. }
  57.  
  58.  
  59. // GLOBAL FUNCTIONS
  60. int TTracer::fReferenceCount = 0;                // initialize with zero value
  61.  
  62. // this will construct a global/universal tracer
  63. TTracer gGlobalTracer("gGlobalTracer",
  64.                       TRACEPOINT);
  65.  
  66.  
  67. // _________________________________________________________________________________________________________ //
  68.  
  69. /*    Change History (most recent last):
  70.   No        Init.    Date        Comment
  71.   1            khs        7/10/92        New file
  72. */
  73.